package com.sugree.util;

import java.io.BufferedInputStream;
import java.io.IOException;

import java.net.URL;
import java.net.URLConnection;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.content.res.Resources;
import android.os.AsyncTask;
import android.text.Html;
import android.widget.ImageView;
import android.util.Log;

public class DownloadTasks {
	protected static final String TAG = "DownloadTasks";

	public static Drawable getDrawable(Resources resources, String source) {
		try {
			final URLConnection conn = new URL(source).openConnection();
			conn.connect();
			final BufferedInputStream bis = new BufferedInputStream(conn.getInputStream());
			final Bitmap bm = BitmapFactory.decodeStream(bis);
			final Drawable d = new BitmapDrawable(resources, bm);
			d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
			bis.close();
			return d;
		} catch (Exception e) {
			Log.d(TAG, e.toString());
			return null;
		}
	}

	/*
	public class ImageGetter extends AsyncTask<Object, Integer, Drawable> {
		private ImageView mView;

		protected Drawable doInBackground(Object... args) {
			String url = args[0];
			mView = args[1];
		}

		protected void onProgressUpdate(Integer... progress) {
		}

		protected void onPostExecute(Drawable result) {
			mView.setImageDrawable(result);
		}
	}
	*/
}
